package com.example.book.controller;

import com.alibaba.fastjson.JSON;
import com.example.book.common.MemberFactory;
import com.example.book.model.Member;
import com.example.book.model.Order;
import com.example.book.service.BookServiceServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class BookController {

    @Autowired
    BookServiceServiceImpl bookServiceService;
    /**
     * 添加会员
     * @param type
     * @return
     */
    @RequestMapping(value = "/addMember",method = RequestMethod.POST)
    public String addMember(@RequestParam("type") int type){
        Member member = MemberFactory.getMember(type);
        bookServiceService.addMember(member);
        return "scucess";
    }

    /**
     * 提交订单
     * @param order
     */
    @RequestMapping(value = "/insertOrder",method = RequestMethod.POST)
    public String insertOrder(Order order){
        bookServiceService.insertOrder(order);
        return "scucess";
    }

    /**
     * 查询订单
     * 支持全查 根据会员ID 订单ID 的定向查
     * @return
     */
    @RequestMapping(value = "/qryOrders",method = RequestMethod.POST)
    @ResponseBody
    public String qryOrders(Map<String,String> map){
        List<Order> orders = bookServiceService.qryOrders(map);
        System.out.println(JSON.toJSONString(orders));
        return JSON.toJSONString(orders);
    }

}
